#ifndef TLB_H_
#define TLB_H_

#include <iostream>
#include <fstream>
#include <stdint.h>
#include <utility>

#include "../../engine/address.hpp"
#include "../../utils/libcache/CacheWriteBack.hpp"

#define    TLB_MISS         0
#define    TLB_HALFMISS     2
#define    TLB_HIT          3
#define    TLB_ERROR        4


/**
 *\ingroup modules
 * TLB is LRU Cache Translation Lookaside Buffer.
 * @author: Carlos Villavieja (cvillavi@ac.upc.edu), June 2010
 */

class TLB {
    private:
        CacheWriteBack <address_t> * _myTLB;
        uint32_t _TLB_size;
        uint32_t _threadID;
        uint32_t _pagesize;
        uint32_t _tlbhits;
        uint32_t _tlbmisses;

    public:
        TLB(uint32_t size,uint32_t pagesize,uint32_t threadID);
        virtual ~TLB();

        virtual void flush(const uint32_t page);
        uint32_t translate( address_t target,address_t &physical);
        void insert(address_t target,address_t physical);
        inline uint32_t getTlbHits() {return _tlbhits;}
        inline uint32_t getTlbMisses() {return _tlbmisses;}
};

#endif /*TLB_H_*/
